import { NextResponse } from 'next/server';

export async function GET() {
  const openApiSpec = {
    openapi: "3.0.0",
    info: {
      title: "卖家后台管理系统 API",
      description: "卖家后台管理系统的完整REST API文档，支持产品、库存、订单、客户管理等功能",
      version: "1.0.0",
      contact: {
        name: "API支持",
        email: "support@seller.com"
      }
    },
    servers: [
      {
        url: "http://localhost:3000/api",
        description: "开发环境"
      }
    ],
    tags: [
      { name: "products", description: "产品管理相关接口" },
      { name: "inventory", description: "库存管理相关接口" },
      { name: "orders", description: "订单管理相关接口" },
      { name: "customers", description: "客户管理相关接口" }
    ],
    paths: {
      "/products": {
        get: {
          tags: ["products"],
          summary: "获取产品列表",
          description: "获取所有产品的列表，支持分页和筛选",
          responses: {
            "200": { description: "成功获取产品列表" },
            "500": { description: "服务器错误" }
          }
        },
        post: {
          tags: ["products"],
          summary: "创建新产品",
          description: "创建一个新的产品",
          requestBody: {
            required: true,
            content: {
              "application/json": {
                schema: { $ref: "#/components/schemas/CreateProductRequest" }
              }
            }
          },
          responses: {
            "201": { description: "产品创建成功" },
            "400": { description: "请求参数错误" },
            "500": { description: "服务器错误" }
          }
        }
      }
    },
    components: {
      schemas: {
        Product: {
          type: "object",
          properties: {
            id: { type: "integer", example: 1 },
            name: { type: "string", example: "iPhone 15 Pro" },
            description: { type: "string", example: "最新款iPhone手机" },
            price: { type: "number", format: "float", example: 6999.99 },
            sku: { type: "string", example: "SKU-001" },
            imageUrl: { type: "string", example: "https://example.com/image.jpg" },
            category: { type: "string", example: "电子产品" },
            createdAt: { type: "string", format: "date-time" },
            updatedAt: { type: "string", format: "date-time" }
          }
        },
        CreateProductRequest: {
          type: "object",
          required: ["name", "price"],
          properties: {
            name: { type: "string", example: "iPhone 15 Pro" },
            description: { type: "string", example: "最新款iPhone手机" },
            price: { type: "number", format: "float", example: 6999.99 },
            sku: { type: "string", example: "SKU-001" },
            imageUrl: { type: "string", example: "https://example.com/image.jpg" },
            category: { type: "string", example: "电子产品" }
          }
        }
      }
    }
  };

  return NextResponse.json(openApiSpec);
}